package cn.ccit.servers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.ccit.DAO.UserAuthorityDAO;
import cn.ccit.DAOImp.UserAuthorityDAOimp;
import cn.ccit.base.BaseConstants;
import cn.ccit.entites.UserAuthority;
import cn.ccit.iservers.IUserAuthorityServers;
import cn.ccit.util.ConstantsUtil;
/**
 * 
 * ClassName: UserAuthorityServers <br/> 
 * Function: 用户权限服务类 <br/> 
 * Reason: TODO ADD REASON(可选). <br/> 
 * date: 2016年11月5日 下午3:22:55 <br/> 
 * 
 * @author Administrator 
 * @version  
 * @since JDK 1.6
 */
public class UserAuthorityServers implements IUserAuthorityServers  {
	private UserAuthorityDAO uaDAO;
	public UserAuthorityServers() {
		uaDAO=new UserAuthorityDAOimp();
	}
	@Override
	public boolean addUserAuthority(UserAuthority ua) {
		Map<String, String> timeMap=ConstantsUtil.getNowTimeMap();
		ua.setCreatTime(timeMap.get(BaseConstants.DATE));
		ua.setLastModfiyTime(timeMap.get(BaseConstants.DATE));
		return uaDAO.addUserAuthority(ua);
	}

	@Override
	public boolean removeUserAuthority(UserAuthority ua) {
		return uaDAO.removeUserAuthority(ua);
	}

	@Override
	public boolean changeUserAuthorityInfo(UserAuthority ua) {
		Map<String, String> timeMap=ConstantsUtil.getNowTimeMap();
		ua.setLastModfiyTime(timeMap.get(BaseConstants.DATE));
		return uaDAO.changeUserAuthorityInfo(ua);
	}

	@Override
	public List<UserAuthority> getSomeUserAuthoritys(int start, int limit) {
		
		return uaDAO.getSomeUserAuthoritys(start, limit);
	}

	@Override
	public UserAuthority searchUserAuthorityByID(int id) {
		return uaDAO.searchUserAuthorityByID(id);
	}
	
	@Override
	public List<UserAuthority> getUserAuthoritiesFromIdList(String idList) {
		List<UserAuthority> list=new ArrayList<UserAuthority>();
		String id[]=idList.split(",");
		for (String string : id) {
			if(ConstantsUtil.getIntegerFromStringNum(string)!=-1){
				list.add(
					uaDAO.searchUserAuthorityByID(
							ConstantsUtil.getIntegerFromStringNum(string)
							)
						);
			}else{
				return null;
			}
		}
		
		return list;
	}
	
}
